Repository navigation
CORS: reject '*' with credentials, add Vary: Origin and an origin matcher - #1614
Merged
Merged
Conversation
…cher - Allowing credentials together with the '*' origin is rejected with an IllegalStateException (CorsService.createInboundFilter, CorsFilter.start); CorsFilter adds no CORS headers with such a configuration. - Vary: Origin is added when the CORS answer depends on the request origin (origin allow-list or credentials), including for requests without Origin; a static '*' without credentials sends no Vary (Fetch standard). - CorsFilter setters now apply after the first request (the helper is rebuilt). - Optional origin matcher (setAllowedOriginMatcher). - Restlet.handle() no longer throws a NullPointerException when a restlet without context cannot be started. - Javadoc references the Fetch standard instead of the W3C CORS draft. Refs #1611 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Refs #1611 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The aim
Refs #1611
Make CORS safe behind shared caches and with credentials, following the Fetch standard (CORS protocol, "CORS protocol and HTTP caches") and RFC 9110 section 12.5.5.
Vary: Originwas never sent (shared caches could mix origins).*allowed together with credentials makes the filter echo any request origin withAccess-Control-Allow-Credentials: true.CorsFilterafter its first request had no effect.The solution
Breaking:
*origin is rejected with anIllegalStateException, whenCorsServicecreates its filter or whenCorsFilterstarts (so the order of the setters doesn't matter). If the filter could not be started,afterHandleadds no CORS headers (fails closed).CorsFiltersetters rebuild the internal helper, so changes after the first request are applied.Non breaking:
Vary: Originis added when the answer depends on the origin (credentials, or allowed origins without*), including requests withoutOrigin; none for a static*.setAllowedOriginMatcher(Predicate<String>)onCorsService,CorsFilter,CorsResponseHelper; the response carries the exact request origin.Restlet.handle(): no moreNullPointerExceptionwhen a restlet without context cannot be started (found while testing the fail-closed path).Not done: Private Network Access; checks of
*inAllow-Headers/Allow-Methods(Restlet never writes a literal*there).Reproduction
new CorsService()withsetAllowedCredentials(true)and the default origins now fails atcreateInboundFilterwith a message asking to list the origins.Check-list
Companions for 2.7 and 2.6 (non breaking part only).
🤖 Generated with Claude Code